package jcl;

import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.testing.RobotTestBed;
import static org.junit.Assert.assertEquals;

/**
 * Tests to see if MajorTom can beat Interactive.
 * 
 * @author Jerry Lau
 * 
 */
public class TestMajorTomVersusInteractive extends RobotTestBed {

  /**
   * Gets the name of the robots which will battle.
   * 
   * @return The list of robots in the match.
   */
  public String getRobotNames() {
    return "sample.Interactive,jcl.MajorTom";
  }

  /**
   * Runs for 10 rounds.
   * 
   * @return Number of rounds
   */
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks if the robot wins all rounds.
   * 
   * @param event Battle info
   */
  public void onBattleCompleted(BattleCompletedEvent event) {
    BattleResults[] battleResults = event.getIndexedResults();
    BattleResults majorTomResults = battleResults[1];
    String robotName = majorTomResults.getTeamLeaderName();
    assertEquals("Check results[1]", robotName, "jcl.MajorTom*");
    assertEquals("Check MajorTom winner", majorTomResults.getFirsts(), getNumRounds());

  }

  /**
   * Returns a comma or space separated list like: x1,y1,heading1, x2,y2,heading2, which are the
   * coordinates and heading of robot #1 and #2. So "0,0,180, 50,80,270" means that robot #1 has
   * position (0,0) and heading 180, and robot #2 has position (50,80) and heading 270.
   * 
   * Override this method to explicitly specify the initial positions for your test cases.
   * 
   * Defaults to null, which means that the initial positions are determined randomly. Since battles
   * are deterministic by default, the initial positions are randomly chosen but will always be the
   * same each time you run the test case.
   * 
   * @return The list of initial positions.
   */
  public String getInitialPositions() {
    return null;
  }

  /**
   * Returns true if the battle should be deterministic and thus robots will always start in the
   * same position each time.
   * 
   * Override to return false to support random initialization.
   * 
   * @return True if the battle will be deterministic.
   */
  @Override
  public boolean isDeterministic() {
    return true;
  }
}